package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.rank.RankProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.union.unionrank.CrossUnionRankMsgCacheMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = CrossProtocol.C_CROSS_UNION_GROUP_UNION_RANK,desc = "跨服商会分组榜单")
public class GetCrossUnionGroupRankCmd extends CrossCommand {


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        RankProto.CrossGroupUnionRankReqMsg req = RankProto.CrossGroupUnionRankReqMsg.parseFrom(packet.getBytes());
        String unionUid = req.getUnionId();

        RankProto.UnionRankListMsg saveRankMsg = CrossUnionRankMsgCacheMgr.getServerUnionGroupRankMsg(serverId);

        RankProto.UnionRankRespMsg.Builder respMsg = RankProto.UnionRankRespMsg.newBuilder();
        respMsg.setMyRank(-1);
        for (int i = 0; i < saveRankMsg.getRankListList().size(); i++) {
            RankProto.UnionRankTempMsg tempMsg = saveRankMsg.getRankListList().get(i);
            if (tempMsg.getUnionUid().equals(unionUid)) {
                respMsg.setMyRank(i + 1);
                break;
            }
        }
        respMsg.setRankList(saveRankMsg);
        YanQuMessage message = YanQuMessageUtils.buildMessage(Protocol.U_UNION_RANK_LIST, respMsg);
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), message);
    }

    @Override
    public void sendData() {

    }
}
